import { mapState } from "vuex";
export const routeMixin = {
  data() {
    return {
      currentPath: '',
      currentName: '',
      siblingNameList: [],
      siblingPathList: [],
      siblingMenuList: []
    }
  },
  computed: {
    ...mapState({
      // 授权后台菜单
      permissionMenuList: state => state.user.authPermissionList
    })
  },
  created() {
    this.getPage()
  },
  methods: {
    // 获取当前权限模块
    getPage() {
      this.currentPath = this.$route.path
      this.currentName = this.$route.name
      this.findCurrentRouteArr(this.permissionMenuList, this.currentPath)
    },
    // 查找当前路由所在的路由列表
    findCurrentRouteArr(menus, key) {
      for (let i of menus) {
        if (i.children && i.children.length > 0) {
          if (i.path == key) {
            let list = i.children.filter(item => item.path != key)
            this.siblingMenuList = list
            this.siblingNameList = list.map(e => e.name)
            this.siblingPathList = list.map(e => e.path)
            break
          } else {
            this.findCurrentRouteArr(i.children, key)
          }
        }
      }
    }
  },
}